package com.longcai.piaojia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.db.BaseTable;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/10/19.
 */
public class MessageAdapter extends ArrayAdapter<BaseTable.BaseA>{

    private LayoutInflater layoutInflater;
    private Context context;

    public MessageAdapter(Context context, List<BaseTable.BaseA> lists) {
        super(context, 0, lists);

        this.layoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder ;

        BaseTable.BaseA str = getItem(position);

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_message_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.item_message_title_tv.setText(str.message);
        viewHolder.item_message_time_tv.setText(str.time);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_message_title_tv) private TextView item_message_title_tv;
        @BoundView(R.id.item_message_time_tv) private TextView item_message_time_tv;

    }

}
